home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
-
- File: sfx main window.c
-
- Purpose: This module handles initializing/drawing/dealing with the
- main window.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program in a file named "GNU General Public License".
- If not, write to the Free Software Foundation, 675 Mass Ave,
- Cambridge, MA 02139, USA.
-
- \**********************************************************************/
-
- #include "sfx main window.h"
- #include "sfx lists.h"
- #include "sfx meat.h"
- #include "environment.h"
- #include "buttons.h"
- #include "util.h"
- #include "main.h"
- #include "error.h"
-
- #define HEADER_SPACE 10
- #define DEAD_SPACE_V 10
- #define DEAD_SPACE_H 10
- #define FOOTER_SPACE 10
- #define PICTURE_HEIGHT -10
- #define BUTTON_HEIGHT 60
- #define BUTTON_WIDTH 60
- #define LIST_HEIGHT 156
- #define LIST_WIDTH 150
- #define TITLE_SPACE_V 20
-
- /* internal procedures for sfx main window.c only */
- static void SetupTheMainWindow(WindowDataHandle theData);
- static void ShutDownTheMainWindow(WindowDataHandle theData);
- static void InitializeTheMainWindow(WindowDataHandle theData);
- static void OpenTheMainWindow(WindowDataHandle theData);
- static void CloseTheMainWindow(WindowDataHandle theData);
- static void IdleInMainWindow(WindowDataHandle theData);
- static void KeyPressedInMainWindow(WindowDataHandle theData, unsigned char theChar);
- static void MouseClickedInMainWindow(WindowDataHandle theData, Point thePoint);
- static void DisposeTheMainWindow(WindowDataHandle theData);
- static void ActivateTheMainWindow(WindowDataHandle theData);
- static void DeactivateTheMainWindow(WindowDataHandle theData);
- static void DrawTheMainWindow(WindowDataHandle theData, short theDepth);
- static void CopybitsTheMainWindow(WindowDataHandle theData);
- static void SwitchLists(WindowDataHandle theData, Boolean updateNow);
- static enum ErrorTypes PickAModule(void);
-
- #define BUTTON_TITLE_ID 200 /* ID of STR# resource of button titles */
- #define BUTTON_INACTIVE_TITLE_ID 201
- #define FIRST_BUTTON_ID 200 /* ID of cicn/ICON resource of first button */
- #define NUM_BUTTONS 3
-
- enum
- {
- kRemoveButton=0, kDemoButton, kInstallButton
- };
-
- static short gOldForegroundTime; /* stored foreground wait time */
- static short gDisplayedScore;
- static ListHandle gUsedList, gNotUsedList;
- static Rect gUsedListRect, gNotUsedListRect;
- static Boolean gUsedIsActive;
- static Rect gButtonRect[NUM_BUTTONS];
- static Str31 gButtonTitle[NUM_BUTTONS];
- static Str31 gButtonInactiveTitle[NUM_BUTTONS];
- static CIconHandle gButtonIconColor[NUM_BUTTONS];
- static Handle gButtonIconBW[NUM_BUTTONS];
- static Boolean gButtonActive[NUM_BUTTONS];
- static short gNumButtons;
- static Boolean gImmediateUpdate;
-
- short MainWindowDispatch(WindowDataHandle theData, short theMessage,
- unsigned long misc)
- {
- short theDepth;
- unsigned char theChar;
- Point thePoint;
- GrafPtr curPort;
-
- switch (theMessage)
- {
- case kNull:
- IdleInMainWindow(theData);
- return kSuccess;
- break;
- case kUpdate:
- theDepth=misc&0x7fff;
- DrawTheMainWindow(theData, theDepth);
- return kSuccess;
- break;
- case kInitialize:
- InitializeTheMainWindow(theData);
- return kFailure;
- case kOpen:
- OpenTheMainWindow(theData);
- return kSuccess;
- break;
- case kClose:
- CloseTheMainWindow(theData);
- return kSuccess;
- break;
- case kKeydown:
- theChar=misc&charCodeMask;
- KeyPressedInMainWindow(theData, theChar);
- return kSuccess;
- break;
- case kMousedown:
- thePoint.h=(misc>>16)&0x7fff;
- thePoint.v=misc&0x7fff;
- MouseClickedInMainWindow(theData, thePoint);
- return kSuccess;
- break;
- case kActivate:
- ActivateTheMainWindow(theData);
- return kSuccess;
- break;
- case kDeactivate:
- DeactivateTheMainWindow(theData);
- return kSuccess;
- break;
- case kStartup:
- SetupTheMainWindow(theData);
- return kSuccess;
- break;
- case kDispose:
- DisposeTheMainWindow(theData);
- return kSuccess;
- break;
- case kShutdown:
- ShutDownTheMainWindow(theData);
- return kSuccess;
- break;
- case kCopybits:
- CopybitsTheMainWindow(theData);
- return kSuccess;
- }
-
- return kFailure;
- }
-
- void SetupTheMainWindow(WindowDataHandle theData)
- {
- unsigned char *titleStr="\pShutdown FX";
- short i;
-
- gButtonRect[kInstallButton].left=DEAD_SPACE_H*3+LIST_WIDTH;
- gButtonRect[kInstallButton].top=HEADER_SPACE+PICTURE_HEIGHT+DEAD_SPACE_V*2+TITLE_SPACE_V;
- gButtonRect[kInstallButton].right=gButtonRect[kInstallButton].left+BUTTON_WIDTH;
- gButtonRect[kInstallButton].bottom=gButtonRect[kInstallButton].top+BUTTON_HEIGHT;
- i=(LIST_HEIGHT-(DEAD_SPACE_V*2+BUTTON_HEIGHT*2))/2;
- OffsetRect(&gButtonRect[kInstallButton], 0, i);
- gButtonRect[kRemoveButton]=gButtonRect[kDemoButton]=gButtonRect[kInstallButton];
- OffsetRect(&gButtonRect[kDemoButton], 0, BUTTON_HEIGHT+DEAD_SPACE_V*2);
- for (i=0; i<NUM_BUTTONS; i++)
- {
- GetIndString(gButtonTitle[i], BUTTON_TITLE_ID, i+1);
- GetIndString(gButtonInactiveTitle[i], BUTTON_INACTIVE_TITLE_ID, i+1);
- gButtonActive[i]=FALSE;
- if (gHasColorQD)
- gButtonIconColor[i]=GetCIcon(FIRST_BUTTON_ID+i);
- gButtonIconBW[i]=GetIcon(FIRST_BUTTON_ID+i);
- }
- gNumButtons=NUM_BUTTONS-1;
-
- (**theData).maxDepth=8;
- (**theData).windowType=noGrowDocProc;
- (**theData).hasCloseBox=TRUE;
- (**theData).windowWidth=DEAD_SPACE_H*6+LIST_WIDTH*2+BUTTON_WIDTH;
- (**theData).windowHeight=HEADER_SPACE+PICTURE_HEIGHT+TITLE_SPACE_V+LIST_HEIGHT+
- DEAD_SPACE_V*2+FOOTER_SPACE;
- SetIndWindowTitle((**theData).windowIndex, titleStr);
- OpenTheWindow(theData);
- }
-
- void ShutDownTheMainWindow(WindowDataHandle theData)
- {
- if (gModuleName[0]==0x00)
- HandleError(PickAModule(), FALSE, FALSE);
- }
-
- void InitializeTheMainWindow(WindowDataHandle theData)
- {
- }
-
- void OpenTheMainWindow(WindowDataHandle theData)
- {
- GetWindowGrafPtr(theData)->txFont=geneva;
- GetWindowGrafPtr(theData)->txSize=9;
-
- gUsedListRect.left=DEAD_SPACE_H;
- gUsedListRect.top=HEADER_SPACE+PICTURE_HEIGHT+DEAD_SPACE_V*2+TITLE_SPACE_V;
- gUsedListRect.right=gUsedListRect.left+LIST_WIDTH;
- gUsedListRect.bottom=gUsedListRect.top+LIST_HEIGHT;
- gUsedList=MyCreateVerticalScrollingList(GetWindowGrafPtr(theData), gUsedListRect,
- 1, 0);
- (**gUsedList).selFlags=lExtendDrag+lNoRect+lUseSense;
- gNotUsedListRect=gUsedListRect;
- OffsetRect(&gNotUsedListRect, LIST_WIDTH+DEAD_SPACE_H*4+BUTTON_WIDTH, 0);
- gNotUsedList=MyCreateVerticalScrollingList(GetWindowGrafPtr(theData), gNotUsedListRect,
- 1, 0);
- (**gNotUsedList).selFlags=lExtendDrag+lNoRect+lUseSense;
- gUsedIsActive=TRUE;
- gImmediateUpdate=TRUE;
- HandleError(MakeNewLists(FALSE), TRUE, FALSE);
- }
-
- void CloseTheMainWindow(WindowDataHandle theData)
- {
- HandleError(PickAModule(), FALSE, FALSE);
-
- LDispose(gUsedList);
- LDispose(gNotUsedList);
- }
-
- void IdleInMainWindow(WindowDataHandle theData)
- {
- }
-
- void KeyPressedInMainWindow(WindowDataHandle theData, unsigned char theChar)
- {
- EventRecord theEvent;
-
- GetCurrentEvent(&theEvent);
-
- switch (theChar)
- {
- case '\t':
- SwitchLists(theData, TRUE);
- break;
- case 0x01: /* home */
- if (gUsedIsActive)
- LScroll(0, -((**gUsedList).dataBounds.bottom), gUsedList);
- else
- LScroll(0, -((**gNotUsedList).dataBounds.bottom), gNotUsedList);
- break;
- case 0x04: /* end */
- if (gUsedIsActive)
- LScroll(0, ((**gUsedList).dataBounds.bottom), gUsedList);
- else
- LScroll(0, ((**gNotUsedList).dataBounds.bottom), gNotUsedList);
- break;
- case 0x0b: /* page up */
- if (gUsedIsActive)
- LScroll(0, -(**gUsedList).visible.bottom+(**gUsedList).visible.top+1, gUsedList);
- else
- LScroll(0, -(**gNotUsedList).visible.bottom+(**gNotUsedList).visible.top+1, gNotUsedList);
- break;
- case 0x0c: /* page down */
- if (gUsedIsActive)
- LScroll(0, (**gUsedList).visible.bottom-(**gUsedList).visible.top-1, gUsedList);
- else
- LScroll(0, (**gNotUsedList).visible.bottom-(**gNotUsedList).visible.top-1, gNotUsedList);
- break;
- case 0x1e: /* up arrow */
- if (gUsedIsActive)
- LScroll(0, -1, gUsedList);
- else
- LScroll(0, -1, gNotUsedList);
- break;
- case 0x1f: /* down arrow */
- if (gUsedIsActive)
- LScroll(0, 1, gUsedList);
- else
- LScroll(0, 1, gNotUsedList);
- break;
- default:
- if (theEvent.modifiers & cmdKey)
- {
- switch (theChar)
- {
- case 'd':
- case 'D':
- if (gButtonActive[kDemoButton])
- {
- Hit3DButton(&gButtonRect[kDemoButton], gButtonTitle[kDemoButton],
- ((**theData).windowDepth>2) ? (Handle)gButtonIconColor[kDemoButton] :
- gButtonIconBW[kDemoButton], (**theData).windowDepth);
- HandleError(DoTheDemoFade(gUsedIsActive ? gUsedList : gNotUsedList), FALSE, FALSE);
- }
- break;
- case 'i':
- case 'I':
- if ((!gUsedIsActive) && (gButtonActive[kInstallButton]))
- {
- Hit3DButton(&gButtonRect[kInstallButton], gButtonTitle[kInstallButton],
- ((**theData).windowDepth>2) ? (Handle)gButtonIconColor[kInstallButton] :
- gButtonIconBW[kInstallButton], (**theData).windowDepth);
- HandleError(DoTheInstall(theData, gUsedList, gNotUsedList), FALSE, FALSE);
- gButtonActive[kRemoveButton]=gButtonActive[kInstallButton]=
- gButtonActive[kDemoButton]=FALSE;
- (**theData).offscreenNeedsUpdate=TRUE;
- UpdateTheWindow(theData);
- }
- break;
- case 'r':
- case 'R':
- if ((gUsedIsActive) && (gButtonActive[kRemoveButton]))
- {
- Hit3DButton(&gButtonRect[kRemoveButton], gButtonTitle[kRemoveButton],
- ((**theData).windowDepth>2) ? (Handle)gButtonIconColor[kRemoveButton] :
- gButtonIconBW[kRemoveButton], (**theData).windowDepth);
- HandleError(DoTheRemove(theData, gUsedList, gNotUsedList), FALSE, FALSE);
- gButtonActive[kRemoveButton]=gButtonActive[kInstallButton]=
- gButtonActive[kDemoButton]=FALSE;
- (**theData).offscreenNeedsUpdate=TRUE;
- UpdateTheWindow(theData);
- }
- break;
- }
- }
- }
- }
-
- void MouseClickedInMainWindow(WindowDataHandle theData, Point thePoint)
- {
- EventRecord theEvent;
- short i;
- Cell theCell;
- Boolean updateNow;
-
- GetCurrentEvent(&theEvent);
- updateNow=FALSE;
- if (PtInRect(thePoint, &gUsedListRect))
- {
- if (!gUsedIsActive)
- {
- SwitchLists(theData, FALSE);
- updateNow=TRUE;
- }
- MyHandleMouseDownInList(theData, gUsedList, &theEvent, TRUE);
- if ((!gButtonActive[kRemoveButton]) &&
- (MyGetFirstSelectedCell(gUsedList, &theCell)))
- {
- gButtonActive[kRemoveButton]=gButtonActive[kDemoButton]=TRUE;
- (**theData).offscreenNeedsUpdate=updateNow=TRUE;
- }
- else if ((gButtonActive[kRemoveButton]) &&
- (!MyGetFirstSelectedCell(gUsedList, &theCell)))
- {
- gButtonActive[kRemoveButton]=gButtonActive[kDemoButton]=FALSE;
- (**theData).offscreenNeedsUpdate=updateNow=TRUE;
- }
- if (updateNow)
- {
- UpdateTheWindow(theData);
- }
- }
- else if (PtInRect(thePoint, &gNotUsedListRect))
- {
- if (gUsedIsActive)
- {
- SwitchLists(theData, FALSE);
- updateNow=TRUE;
- }
- MyHandleMouseDownInList(theData, gNotUsedList, &theEvent, FALSE);
- if ((!gButtonActive[kInstallButton]) &&
- (MyGetFirstSelectedCell(gNotUsedList, &theCell)))
- {
- gButtonActive[kInstallButton]=gButtonActive[kDemoButton]=TRUE;
- (**theData).offscreenNeedsUpdate=updateNow=TRUE;
- }
- else if ((gButtonActive[kInstallButton]) &&
- (!MyGetFirstSelectedCell(gNotUsedList, &theCell)))
- {
- gButtonActive[kInstallButton]=gButtonActive[kDemoButton]=FALSE;
- (**theData).offscreenNeedsUpdate=updateNow=TRUE;
- }
- if (updateNow)
- {
- UpdateTheWindow(theData);
- }
- }
- else
- {
- for (i=gNumButtons-1; i>=0; i--)
- {
- if ((PtInRect(thePoint, &gButtonRect[i])) && (gButtonActive[i]))
- {
- if (Track3DButton(&gButtonRect[i], gButtonTitle[i],
- ((**theData).windowDepth>2) ? (Handle)gButtonIconColor[i] :
- gButtonIconBW[i], (**theData).windowDepth))
- {
- switch (i)
- {
- case kRemoveButton:
- HandleError(DoTheRemove(theData, gUsedList, gNotUsedList), FALSE, FALSE);
- gButtonActive[kRemoveButton]=gButtonActive[kInstallButton]=
- gButtonActive[kDemoButton]=FALSE;
- (**theData).offscreenNeedsUpdate=TRUE;
- UpdateTheWindow(theData);
- break;
- case kDemoButton:
- HandleError(DoTheDemoFade(gUsedIsActive ? gUsedList : gNotUsedList), FALSE, FALSE);
- break;
- case kInstallButton:
- HandleError(DoTheInstall(theData, gUsedList, gNotUsedList), FALSE, FALSE);
- gButtonActive[kRemoveButton]=gButtonActive[kInstallButton]=
- gButtonActive[kDemoButton]=FALSE;
- (**theData).offscreenNeedsUpdate=TRUE;
- UpdateTheWindow(theData);
- break;
- }
- }
- }
- }
- }
- }
-
- void DisposeTheMainWindow(WindowDataHandle theData)
- {
- }
-
- void ActivateTheMainWindow(WindowDataHandle theData)
- {
- gOldForegroundTime=gForegroundWaitTime;
- gForegroundWaitTime=0;
- LActivate(TRUE, gUsedList);
- LActivate(TRUE, gNotUsedList);
- MyDrawActiveListBorder(gUsedList, gUsedIsActive);
- MyDrawActiveListBorder(gNotUsedList, !gUsedIsActive);
- }
-
- void DeactivateTheMainWindow(WindowDataHandle theData)
- {
- gForegroundWaitTime=gOldForegroundTime;
- LActivate(FALSE, gUsedList);
- LActivate(FALSE, gNotUsedList);
- MyDrawActiveListBorder(gUsedList, FALSE);
- MyDrawActiveListBorder(gNotUsedList, FALSE);
- }
-
- void DrawTheMainWindow(WindowDataHandle theData, short theDepth)
- {
- RGBColor oldForeColor, oldBackColor;
- GrafPtr curPort;
- short i;
-
- if (theDepth>2)
- {
- GetForeColor(&oldForeColor);
- GetBackColor(&oldBackColor);
- }
-
- GetPort(&curPort);
- EraseRect(&(curPort->portRect));
-
- for (i=0; i<gNumButtons; i++)
- Draw3DButton(&gButtonRect[i], gButtonActive[i] ? gButtonTitle[i] :
- gButtonInactiveTitle[i], (theDepth>2) ?
- (Handle)gButtonIconColor[i] : gButtonIconBW[i], theDepth, FALSE);
-
- MoveTo(DEAD_SPACE_H, HEADER_SPACE+PICTURE_HEIGHT+DEAD_SPACE_V+TITLE_SPACE_V-3);
- DrawString("\pCurrently available fade modules:");
-
- MoveTo(DEAD_SPACE_H*5+LIST_WIDTH+BUTTON_WIDTH, HEADER_SPACE+PICTURE_HEIGHT+DEAD_SPACE_V+TITLE_SPACE_V-3);
- DrawString("\pCurrently disabled fade modules:");
-
- if (theDepth>2)
- {
- RGBForeColor(&oldForeColor);
- RGBBackColor(&oldBackColor);
- }
- }
-
- void CopybitsTheMainWindow(WindowDataHandle theData)
- {
- RgnHandle copyRgn;
- RgnHandle listRgn;
-
- copyRgn=NewRgn();
- listRgn=NewRgn();
- RectRgn(copyRgn, &(GetWindowGrafPtr(theData)->portRect));
- RectRgn(listRgn, &gUsedListRect);
- InsetRgn(listRgn, -4, -4);
- DiffRgn(copyRgn, listRgn, copyRgn);
- SetEmptyRgn(listRgn);
- RectRgn(listRgn, &gNotUsedListRect);
- InsetRgn(listRgn, -4, -4);
- DiffRgn(copyRgn, listRgn, copyRgn);
-
- CopyBits(&(GetOffscreenGrafPtr(theData)->portBits),
- &(GetWindowGrafPtr(theData)->portBits),
- &(GetWindowGrafPtr(theData)->portRect),
- &(GetWindowGrafPtr(theData)->portRect), 0, copyRgn);
- DisposeRgn(copyRgn);
- DisposeRgn(listRgn);
-
- LUpdate(GetWindowGrafPtr(theData)->visRgn, gUsedList);
- MyDrawListBorder(gUsedList);
- MyDrawActiveListBorder(gUsedList, gUsedIsActive);
- LUpdate(GetWindowGrafPtr(theData)->visRgn, gNotUsedList);
- MyDrawListBorder(gNotUsedList);
- MyDrawActiveListBorder(gNotUsedList, !gUsedIsActive);
- }
-
- enum ErrorTypes MakeNewLists(Boolean updateNow)
- {
- enum ErrorTypes resultCode;
-
- LDoDraw(FALSE, gUsedList);
- LDoDraw(FALSE, gNotUsedList);
- resultCode=SetUpLists(gUsedList, gNotUsedList);
- if (resultCode!=allsWell)
- return resultCode;
- LDoDraw(TRUE, gUsedList);
- LDoDraw(TRUE, gNotUsedList);
- if (updateNow)
- {
- MyUpdateList(gUsedList);
- MyUpdateList(gNotUsedList);
- }
-
- return allsWell;
- }
-
- void SwitchLists(WindowDataHandle theData, Boolean updateNow)
- {
- if (gUsedIsActive)
- {
- MyDeselectAllCells(gUsedList);
- gNumButtons++;
- }
- else
- {
- MyDeselectAllCells(gNotUsedList);
- gNumButtons--;
- }
- gButtonActive[kRemoveButton]=gButtonActive[kInstallButton]=
- gButtonActive[kDemoButton]=FALSE;
- gUsedIsActive=!gUsedIsActive;
- (**theData).offscreenNeedsUpdate=TRUE;
- if (updateNow)
- {
- UpdateTheWindow(theData);
- }
- }
-
- enum ErrorTypes PickAModule(void)
- {
- Cell theCell;
-
- if ((gUsedList==0L) || ((**gUsedList).dataBounds.bottom==0))
- return kNoModulesInstalled;
-
- if (gChooseRandom)
- {
- gModuleIndex=(Random()&0x7fff)%((**gUsedList).dataBounds.bottom);
- }
- else
- {
- while (gModuleIndex>=(**gUsedList).dataBounds.bottom)
- gModuleIndex-=(**gUsedList).dataBounds.bottom;
- if (gModuleIndex<0)
- gModuleIndex=0;
- }
- SetPt(&theCell, 0, gModuleIndex);
- MyGetCellData(gUsedList, theCell, gModuleName);
-
- return allsWell;
- }
-